package com.yangxk.kadmin.web.module.sample.controller;

import com.yangxk.kadmin.web.module.sample.form.AreaEditForm;
import com.yangxk.kadmin.web.module.sample.service.AreaService;
import com.yangxk.kadmin.web.module.sample.po.Area;
import com.yangxk.kadmin.common.beans.Result;
import com.yangxk.kadmin.web.common.annotation.Permission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class AreaController {
    @Autowired
    private AreaService areaService;

    @GetMapping("/area/tree")
    public Result queryAreaTree() {
        return Result.ofSuccess(areaService.queryAreaTree());
    }

    @PostMapping("/area/add")
    @Permission("area:add")
    public Result add(@RequestBody AreaEditForm form) {
        areaService.addArea(form);
        return Result.ofSuccess();
    }

    @GetMapping("/area/detail")
    public Result<Area> queryById(long id) {
        Area area = areaService.selectByPrimaryKey(id);
        return Result.ofSuccess(area);
    }

    @PostMapping("/area/update")
    @Permission("area:update")
    public Result update(@RequestBody AreaEditForm form) {
        areaService.updateArea(form);
        return Result.ofSuccess();
    }

    @GetMapping("/area/delete")
    @Permission("area:delete")
    public Result delete(long id) {
        areaService.deleteArea(id);
        return Result.ofSuccess();
    }

}
